package face;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;

import face.model.Face;
import face.util.ImageBase64;

public class FaceTest {
	public static void main(String[] args) {
	    String host = "http://rlsbbd.market.alicloudapi.com";
	    String path = "/face/verify";
	    String method = "POST";
	    String appcode = "你自己的AppCode";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + "46920b571b8844a7942dea6a809236fa");
	    //根据API的要求，定义相对应的Content-Type
	    headers.put("Content-Type", "application/json; charset=UTF-8");
	    Map<String, String> querys = new HashMap<String, String>();
//	    String bodys = "{\"type\":0,#0:通过url识别，参数image_url不为空；1:通过图片content识别，参数content不为空\"image_url_1\":\"http://a.com/a.jgp\",#输入图片1的URL\"content_1\":\"\",#输入图片1的content，base64方式编码\"image_url_2\":\"http://a.com/b.jgp\",#输入图片2的URL\"content_2\":\"\"#输入图片2的content，base64方式编码}";
//	    https://help.aliyun.com/knowledge_detail/53535.html?spm=5176.730006-cmapi020044.102.12.WBGHN8
	    Face face = new Face();
    	face.setType(1);
    	face.setContent_1(ImageBase64.getImageStr("C:\\Users\\Administrator\\Pictures\\20170330134958.jpg"));
    	face.setImage_url_1("");
    	face.setContent_2(ImageBase64.getImageStr("C:\\Users\\Administrator\\Pictures\\30134454.jpg"));
    	face.setImage_url_2("");
    	String bodys = JSONObject.toJSONString(face);
    	System.out.println(bodys);
    	try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	
}
